#ifndef __REQUEST_H
#define __REQUEST_H

class CReqItem
{
protected:
    char* m_pName;
    char* m_pVal;
    
    CReqItem* m_pNext;
public:
    CReqItem(char*,char*);
    virtual ~CReqItem(void);
    
    char* GetName(void);
    char* GetVal(void);

    friend class CRequest;
};

#define	STAT_FINDSECTION	0
#define	STAT_APPEND		1
#define	STAT_STOP		2

#define	STAT_UNKNOWN		0
#define	STAT_SECTION		1
#define	STAT_NAME		2
#define	STAT_REM		3
#define	STAT_VALUE		4

#define TMP_BUF_SIZE    254

class CRequest
{
protected:
    CReqItem* m_pBegin,*m_pEnd;
    char* m_pSection;

    int m_nGlobalState;
    int m_nState;
    
    char m_pName[TMP_BUF_SIZE+1];
    int m_nName;
    char m_pVal[TMP_BUF_SIZE+1];
    int m_nVal;
    
    CReqItem* Add(char*,char*);
    bool OnChar(unsigned char);
    void AddName(unsigned char);
    void AddVal(unsigned char);
    void Reset(void);
    char* GetName(void);
    char* GetVal(void);
    
    void OnValue(char*,char*);
    void OnSection(char*);
public:
    CRequest(void);
    virtual ~CRequest(void);
    void Clear(void);

    bool LoadVariables(const char*,const char*);
    const char* GetValue(const char*,const char* item,const char* def="",int* len=0);
};



#endif
